package utils
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.IBitmapDrawable;
	import flash.display.MovieClip;
	
	public class DuplicateDisplayObject {	
		public function DuplicateDisplayObject(){
			
		}

		public function duplicateMovieClip(target:DisplayObject):DisplayObject {
			var targetClass:Class;
			targetClass = Object(target).constructor;
			var duplicado:DisplayObject = new targetClass();
			
			duplicado.transform = target.transform;
			duplicado.filters = target.filters;
			duplicado.cacheAsBitmap = target.cacheAsBitmap;
			duplicado.opaqueBackground = target.opaqueBackground;
			return duplicado;
		}
		
		public function duplicateImageAsSprite(original:DisplayObject ):Sprite
		{
			var bitmapData:BitmapData = new BitmapData( original.width , original.height , true , 0x000000 );
			bitmapData.draw(original as IBitmapDrawable );
			
			var bitmap:Bitmap = new Bitmap( bitmapData );
			
			var returnSprite:Sprite = new Sprite();
			returnSprite.addChild( bitmap as DisplayObject );
			
			return returnSprite;
		}
	}
}